﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace DAMBAOCLPM
{
    public partial class frmDanhsachnopbai : Form
    {
        SqlDataAdapter da;
        public static String sql;
        public frmDanhsachnopbai()
        {
            InitializeComponent();
        }

        private void frmDanhsachnopbai_Load(object sender, EventArgs e)
        {
            clsConnection.CreateConnection();
            this.Width = clsVariables.Width_This - 21;
            this.Height = clsVariables.Height_This - clsVariables.Height_TopMenu - 65;
            this.Top = clsVariables.Height_TopMenu - 66;
            this.Left = 0;
            //Load dư liệu lên combobox đơn vị
            da = new SqlDataAdapter("select * from DONVI", clsConnection.con);
            DataTable tb = new DataTable();
            da.Fill(tb);
            cbodonvi.DataSource = tb;
            cbodonvi.DisplayMember = "TENKHOA";
            cbodonvi.ValueMember = "MAKHOA";
            cbodonvi.Text = "";

        }

        private void cbodonvi_SelectedIndexChanged(object sender, EventArgs e)
        {
            clsConnection.CreateConnection();
            sql = "select a.SBD ,a.HOLOT,a.TEN,a.NGAYSINH,a.NOISINH from THISINH a,BAILAM b where a.SBD=b.SBD and b.TRANGTHAI = 1 and a.MAKHOA = '" + cbodonvi.SelectedValue.ToString() + "'";
            da = new SqlDataAdapter(sql, clsConnection.con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            da.Dispose();
            dt.Columns.Add("STT", Type.GetType("System.Int32"));
            for (int i = 0; i <= dt.Rows.Count - 1; i++)
            {
                dt.Rows[i]["STT"] = i + 1;

            }
            dtvXemdanhsach.DataSource = dt;
        }

        private void btthoat_Click(object sender, EventArgs e)
        {
            DialogResult = MessageBox.Show("Bạn có muốn thoát không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (DialogResult == DialogResult.OK)
            {
                Application.Exit();
            }
        }

        private void btin_Click(object sender, EventArgs e)
        {
            frmRdsnopbai f = new frmRdsnopbai();
            f.Show();
        }

    }
}
